package com.carl.mall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.alibaba.fastjson.JSON;
import net.bytebuddy.agent.builder.AgentBuilder;
import org.apache.catalina.LifecycleState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.carl.mall.product.entity.SkuInfoEntity;
import com.carl.mall.product.service.SkuInfoService;
import com.carl.common.utils.PageUtils;
import com.carl.common.utils.R;



/**
 * sku信息
 *
 * @author carl
 * @email 541020344@qq.com
 * @date 2024-03-10 00:31:47
 */
@RestController
@RequestMapping("product/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:skuinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = skuInfoService.queryPageByCondition(params);

        return R.ok().put("page", page);
    }


    /**
     * 根据skuid 获取器销售属性的组合
     * attr_name:attr:value
     * 选择外观 : 雅川青
     * 选择版本 : 12+512G
     * 套装 : 优惠套装1
     * 原厂服务 : 2年碎屏四年电池：￥367.00
     * @return
     */
    @GetMapping("/saleAttrs/{skuId}")
    public List<String> getSkuSaleAttrs(@PathVariable("skuId")Long skuId){
         return skuInfoService.querySkuSaleAttrsBySkuId(skuId);
    }

    /**
     * 根据sku编号获取sku信息
     */
    @RequestMapping("/info/{skuId}")
    //@RequiresPermissions("product:skuinfo:info")
    public R info(@PathVariable("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);
        return R.ok().put("skuInfo", skuInfo).put("skuInfoJson", JSON.toJSONString(skuInfo));
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:skuinfo:save")
    public R save(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:skuinfo:update")
    public R update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:skuinfo:delete")
    public R delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
